package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationCountDto;
import com.zzyl.dto.VisitDto;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.vo.ReservationCountVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @param
 * @return
 */
@Api(tags = "小程序接口")
@RestController
@RequestMapping("/customer/reservation")
public class CustomerReservationController extends BaseController {

    @Autowired
    private CustomerReservationService customerReservationService;

    //查询取消预约数量
    @GetMapping("/cancelled-count")
    public ResponseResult selectCancelCount() {
        Long count = customerReservationService.selectCancelCount();
        return success(count);
    }

    //新增预约
    @PostMapping
    public ResponseResult insertReservation(@RequestBody VisitDto visitDto) {
        customerReservationService.insertReservation(visitDto);
        return success();
    }

    //分页查询预约
    @GetMapping("/page")
    public ResponseResult pageReservation(Integer pageNum, Integer pageSize, Integer status) {
        PageResponse page = customerReservationService.pageReservation(pageNum, pageSize, status);
        return success(page);
    }

    //取消预约
    @PutMapping("/{id}/cancel")
    public ResponseResult cancelReservation(@PathVariable Integer id) {
        customerReservationService.cancelReservation(id);
        return success();
    }

    //查询每个时间段剩余预约次数
    @GetMapping("/countByTime")
    public ResponseResult selectCountByTime(ReservationCountDto reservationCountDto) {
        List<ReservationCountVo> list = customerReservationService.selectCountByTime(reservationCountDto);
        return success(list);
    }

}
